package dujiu.leetcode.slidingWindow.fixed_lengthSlidingWindow;

public class P643 {
    public double findMaxAverage(int[] nums, int k) {
        int sum = 0;
        for (int i = 0;i<k;i++){
            sum += nums[i];
        }

        int maxSum = sum;
        for (int i = k; i < nums.length; i++) {
            sum = sum - nums[i-k] + nums[i];
            maxSum = Math.max(maxSum,sum);
        }
        return (double) maxSum/k;
    }

    public static void main(String[] args) {
        P643 p = new P643();
        // int[] nums = {1,12,-5,-6,50,3};
        int[] nums = {5};
        System.out.println(p.findMaxAverage(nums, 1));
    }
}
